const request = strParame => {
    var args = {};
    var query = location.search.substring(1);

    var pairs = query.split("&"); // Break at ampersand
    for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos === -1) continue;
        var argname = pairs[i].substring(0,pos);
        var value = pairs[i].substring(pos+1);
        value = decodeURIComponent(value);
        args[argname] = value;
    }
    return args[strParame];
};
let bookName = request("name");
let bid = request("bid");
var title = document.getElementById("title");

//添加书籍名称
if(bookName!==undefined){
    title.innerText = bookName;
}
window.onload =function () {
    var loadBtn = document.getElementById("btn-load");
    loadBtn.onclick =function () {
        let name = document.getElementById("name");
        let content = document.getElementById("content");
        if(name.value===""){
            name.style.border="1vw solid #f0683e";
        }
        if(content.value===""){
            content.style.border="1vw solid #f0683e";
        }
        //全不为空发送信息到服务器
        if(name.value!=="" && content.value!==""){
            this.disabled="disabled";
            loadBtn.value="上传中";
            axios.get("addBookWord?bid="+bid+"&name="+name.value+"&content="+content.value)
                .then(function (response) {
                    if(response.data.isSuccess){
                        alert("上传成功！");
                    }else {
                        loadBtn.disabled="";
                        loadBtn.value="提交";
                        alert("上传失败！请稍后再试");
                    }
                })
        }
    }
}